package lin.tb.com.commonadapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by zhenggl on 2015/8/11.
 */
public abstract class CommonBaseAdapter<T> extends BaseAdapter {

    private Context context;
    private List<T> entityList;

    public CommonBaseAdapter(Context context, List<T> entityList){
        this.context = context;
        this.entityList = entityList;
    }

    @Override
    public int getCount() {
        if(entityList != null && !entityList.isEmpty()){
            return entityList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return entityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CommonViewHolder holder = CommonViewHolder.get(context, convertView, R.layout.item, parent, position);
        initView(holder, entityList.get(position));
        return holder.getConvertView();
    }

    public abstract void initView(CommonViewHolder holder, T t);
}
